import { setTableData, addTableData, changeTableData, getTableData } from "../../utils/tableData"

// 存储信息
export const setBillData = () => {
  return async (dispatch) => {
    let data = setTableData()
    dispatch({
      type: 'setBillData',
      payload: data
    })
    setTableData()
  }
}

// 增加表格信息
export const addBillData = (data) => {
  return async (dispatch) => {
    dispatch({
      type: 'addBillData',
      payload: data
    })
    addTableData(data)
  }
}
// 修改表格信息
export const changeBillData = (data) => {
  return async (dispatch) => {
    dispatch({
      type: 'changeBillData',
      payload: data
    })
    changeTableData(data)
  }
}
// 查询表格信息
export const getBillData = (data) => {
  const datax = JSON.parse(getTableData())
  // console.log(data)
  if (data === undefined) {
    data = [['', undefined], [...datax]]
    // console.log(data)
  } else {
    data = [[...data], [...datax]]
  }
  return async (dispatch) => {
    dispatch({
      type: 'getBillData',
      payload: data
    })
  }
}